<?php

class Flags{
  public function __construct(dataBaseConnection $connection) {
    $this->Connection=$connection;
  }
  
  public function GetAllFlags($addLimit) {
    $queries=new mysqlqueries();
    $query=$queries->GetTable($queries->Flag, "date DESC");
    if(!$addLimit)
    {
      $query=$queries->AddLimit($query, 0, 30);
    }
    $result = $this->Connection->query($query);
    $return = array();
    while ($row = mysqli_fetch_array($result)) {
      array_push($return, array($row["date"],$row["name"],$row["flag"]));
    }
    return $return;
  }
  
  public function GetLastFlagOfType($type) {
    $queries=new mysqlqueries();
    $query=$queries->AddLimit($queries->GetIndex($queries->Flag,$type,"name", "date DESC"), 0, 1);
    $result = $this->Connection->query($query);
    $flag = 0;
    if($row = mysqli_fetch_array($result))
    {
      $flag = $row["flag"];
    }
    return $flag;
  }
  
  public function RemoveAllFlags()
  {
    $queries = new mysqlqueries();
    $this->Connection->query($queries->TruncateTable($queries->Flag));
  }
  public $Connection;
}